// import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import query from '@dfeidao/atom-nodejs/db/query';
import { systemid, productid } from '../../atom/config';
import count from '@dfeidao/atom-nodejs/db/count';
import format from '@dfeidao/atom-nodejs/dt/format';


interface Message {

	event_theme: string;
	safety_department_no: string;

	page_no: number;
}

// 表名	burst_event				
// 标题	突发事件				
// 字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
// _id	id	string	50	ⅹ	√
// productid	产品ID	string	50	√	ⅹ
// event_no	事件编号	string	32	√	ⅹ
// event_theme	事件主题	string	32	√	ⅹ
// management_office	管理处	string	64	√	ⅹ
// principal_part	负责部门	string	32	√	ⅹ
// event_time	事发时间	timestamp	50	√	ⅹ
// event_location	事发地点	string	64	√	ⅹ
// event_record	事件记录	string	128	√	ⅹ
// process_result	处理结果	string	128	√	ⅹ
// cause_analysis	原因分析	string	128	√	ⅹ
// precaution	预防措施	string	128	√	ⅹ
// principal_opinion	负责人意见	string	128	√	ⅹ
// report_time	报告时间	timestamp	50	√	ⅹ
// reporter_no	报告人编号	string	32	√	ⅹ
// reporter_name	报告人姓名	string	32	√	ⅹ
// resume_attachment	附件	document	50	√	ⅹ
// memo	备注	string	500	√	ⅹ
// annex_name	附件名称	string	50	√	ⅹ
// management_office_no	管理处编号	string	32	√	ⅹ
// principal_part_no	负责部门编号	string	32	√	ⅹ


export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	// log('Service begin path:e:\7.29考核\kh\src\LiQiuLiang\zj-000001\s001,action_id:' + action_id);

	const q = query(action_id, session_id, systemid);


	q.prepare('burst_event', ['event_no', 'event_theme', 'principal_part', 'principal_part_no', 'event_time', 'event_location', 'report_time', 'reporter_name',], { productid, event_theme: { $like: '%' + message.event_theme + '%' }, principal_part: { $like: '%' + message.safety_department_no + '%' } }, 10, message.page_no, [], []);
	const [qq] = await q.exec<{ event_time: string, report_time: string }>();

	const res1 = qq.map((v) => {
		const nowdata = new Date(v.event_time).getTime();
		const new_data = format(nowdata, 'YYYY-MM-DD HH:mm:ss');
		const nowdata1 = new Date(v.report_time).getTime();
		const new_data1 = format(nowdata, 'YYYY-MM-DD HH:mm:ss');
		return { ...v, new_data, new_data1 }
	})
	// const q1 = query(action_id, session_id, systemid);
	// q1.prepare('security_architecture', ['safety_department_no', 'safety_department_name'], { productid, }, 200, 1, [], []);
	// const [qqq] = await q1.exec();




	const { prepare, exec } = count(action_id, session_id, systemid);
	prepare('burst_event', { productid, event_theme: { $like: '%' + message.event_theme + '%' }, principal_part: { $like: '%' + message.safety_department_no + '%' } });
	const [c] = await exec();



	// log('Service end path:e:\7.29考核\kh\src\LiQiuLiang\zj-000001\s001,action_id:' + action_id);
	return {
		data: {
			qq, c, res1
		}
	}
}
